<template>
  <div class="games-container">
    <h2>打字小游戏</h2>
    <div class="games-list">
      <div
        v-for="game in games"
        :key="game.path"
        :class="['game-card', { disabled: !isLogin }]"
        @click="goGame(game.path)"
        :tabindex="isLogin ? 0 : -1"
        :aria-disabled="!isLogin"
      >
        <span v-if="!isLogin" class="lock">🔒</span>
        <span class="game-title">{{ game.title }}</span>
        <span class="game-desc">{{ game.desc }}</span>
      </div>
    </div>
    <div v-if="!isLogin" class="tip">请先登录后再玩小游戏</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'TypingGames',
  data() {
    return {
      games: [
        { title: '单词雨', path: '/games/rain', desc: '打落下的单词，提升反应力' },
        { title: '限时挑战', path: '/games/challenge', desc: '限时打字，看你能打多少' },
        { title: '跟打名言', path: '/games/quote', desc: '跟打名人名言，提升准确率' }
      ]
    }
  },
  computed: {
    ...mapState('user', ['isLogin'])
  },
  methods: {
    goGame(path) {
      if (this.isLogin) {
        this.$router.push(path)
      }
    }
  }
}
</script>

<style scoped>
.games-container {
  max-width: 700px;
  margin: 40px auto;
  padding: 2rem;
  background: var(--hover-color);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.games-list {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 2rem;
}
.game-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  padding: 1.5rem 2rem;
  min-width: 180px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s;
  position: relative;
}
.game-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  background: #f0f8ff;
}
.game-card.disabled {
  background: #f5f5f5;
  color: #bbb;
  cursor: not-allowed;
  pointer-events: none;
}
.lock {
  margin-right: 0.5em;
  font-size: 1.2em;
}
.game-title {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}
.game-desc {
  font-size: 0.95rem;
  opacity: 0.7;
}
.tip {
  color: #dc3545;
  text-align: center;
  margin-top: 2rem;
  font-size: 1.1rem;
}
</style> 